import TWEEN from "@tweenjs/tween.js";
const cameraFlyTO = (target, camera, controls, time = 10) => {
  const originPos = camera.position
  const targetPos = {
    x: target.position.x - 12,
    y: target.position.y + 15,
    z: target.position.z - 3
  }
  const distance = originPos.distanceTo(targetPos)
  let cameraPosAni = new TWEEN.Tween(originPos).to(targetPos, distance * time).easing(TWEEN.Easing.Cubic.InOut)
  cameraPosAni.delay(800);
  cameraPosAni.onUpdate(() => {
    camera.position.set(originPos.x, originPos.y, originPos.z);
    camera.lookAt(originPos.x, originPos.y, originPos.z);
    controls.target.set(0, 0, 0);
    controls.update();
  }).onComplete(() => {
  })
  cameraPosAni.start();
  return cameraPosAni;
}
export { cameraFlyTO, TWEEN };